package com.api.shopapi.mapper;



import com.api.shopapi.entity.Version;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface VersionMapper {

    @Insert("insert into version values " +
            "(" +
            "#{version.VersionCode}," +
            "#{version.Name}," +
            "#{version.Version}," +
            "#{version.Url}" +
            ")")
    public int insert(@Param("version") Version version);

    @Delete("delete from version where VersionCode=#{versionCode}")
    public int delete(@Param("versionCode") String versionCode);

    @Update("update version set " +
            "Name = #{version.Name}," +
            "Version = #{version.Version}," +
            "Url=#{version.Url} "+
            " where VersionCode =#{version.VersionCode}")
    public int update(@Param("version") Version version);


    @Select("select * from version where VersionCode=#{versionCode} limit 1")
    public Version getByVersionCode(@Param("versionCode") String versionCode);

    @Select("select * from version where Name=#{name} limit 1")
    public Version getByName(@Param("name") String name);

    @Select("select * from version where Version=#{version} limit 1")
    public Version getByVersion(@Param("version") String version);

    @Select("<script>" +
            "select * from version where 1=1 " +
            "<if test ='name !=null and name!=\"\" '>" +
            " and Name like concat('%',#{name},'%') " +
            "</if>" +
            "<if test ='version !=null and version!=\"\" '>" +
            " and Version like concat('%',#{version},'%') " +
            "</if>" +
            "</script>")
    List<Version> getPageList(@Param("name") String name,@Param("version") String version);

}
